#include <iostream>
using namespace std;

//分步实现
/*class A{
private:
	int x;
public:
	A(int t){
		this->x = t;
	}
	void fun(){
		cout << "x=" << x << endl;
	}
};

class B{
private:
	int y;
public:
	B(int t){
		this->y = t;
	}
	void fun(){
		cout << "y=" <<y << endl;
	}
};

class C{
private:
	int z;
public:
	C(int t){
		this->z = t;
	}
	void fun(){
		cout << "z=" << z << endl;
	}
};

class my{
private:
	A *a;
	B *b;
	C *c;
public:
	my(){
		a = new A(3);
		b = new B(4);
		c = new C(5);
	}
	void doFun(){
		a->fun();
		b->fun();
		c->fun();
	}
	~my(){
		delete a;
		delete b;
		delete c;
	}
};

int main(void){
	my *p = new my();
	p->doFun();
	delete p;
	return 0;
}*/

//使用链表
class A{
private:
    int data;
    A* next;
public:
    A(){
        this->data = 0;
        this->next = NULL;
    }
    A(int data){
        this->data = data;
        this->next = NULL;
    }

    void Set(A *t){
        next = t;
    }

    void print(){
        //递归
        cout << "data=" << data << endl;
        if (next)
            next->print();
    }

    ~A(){
        delete next;
    }
};

int main(void){
    A *p, *h = NULL;
    p = h;
    int x;
    for (int i = 0; i < 4; ++i){
        cout << "请输入一个数值：" ;
        cin >> x;
        p = new A(x);
        p->Set(h);
        h = p;
    }
    h->print();
    delete h;
    return 0;
}